package cur.tool;

import cur.nature.framework.core.log.LOG;
import cur.nature.tinyorm.core.template.DefaultJdbcTemplate;
import cur.tool.common.table.CreateTable;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.event.ContextClosedEvent;

@Configuration
@DependsOn(DefaultJdbcTemplate.TEMPLATE)
public class ToolListener {

    @Bean
    public ApplicationListener onToolDemoStart(@Qualifier(DefaultJdbcTemplate.TEMPLATE) DefaultJdbcTemplate template) {
        return (ApplicationListener<ApplicationReadyEvent>) event -> {
            CreateTable.process(template);
            LOG.info("项目 ToolDemo 已启动-------------------------------");
        };
    }

    @Bean
    public ApplicationListener onToolDemoStop() {
        return (ApplicationListener<ContextClosedEvent>) event -> {
            LOG.info("项目 ToolDemo 已停止-------------------------------");
        };
    }
}
